package sortEvenOdd;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Solution {
    public int[] sortEvenOdd(int[] nums) {
        List<Integer> odd = new ArrayList<>(); // 奇数
        List<Integer> even = new ArrayList<>(); // 偶数
        for (int i = 0; i < nums.length; i+=2) {
            even.add(nums[i]);
            if(i+1<nums.length){
                odd.add(nums[i+1]);
            }
        }
        Collections.sort(odd, (o1, o2) -> o1 - o2);
        Collections.sort(even, (o1, o2) -> o2 - o1);
        int index = 0;
        int i = 0;
        while (index<nums.length){
            if(i<even.size())
            nums[index] = even.get(i);
            if(i<odd.size())
            nums[index] = odd.get(i);
            index++;
        }
        return nums;
    }
}
